package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: ListStudents
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for SE 17-655, Architectures for Software Systems. This is a
** stand alone thread that will list the students currently in the Student list.
**
** Abstract: Upon notification, this thread will list the students that were read into
** the vector stored in the DataObject class.
**
**
** Modification Log
**************************************************************************************
** Modification by: A.J. Lattanze
** Date: 01/24/02
** Version 1.5
** Description: This class has been changed to run as a stand-alone thread. This
** method was changed to implement the Runnable class so that it could run as a thread.
** While, this has little impact on the architecture, it illustrates a multi-threaded
** event model.
**************************************************************************************/
import java.util.*;

public class ListStudents extends Communication implements Runnable
{
	boolean Stop = false;

	public ListStudents( Integer RegistrationNumber, String ComponentName )
	{
		super( RegistrationNumber, ComponentName  );

	} // Constructor

	public void update( Observable Thing, Object NotificationNumber )
	{
		// The update() method is an abstract method that is called whenever the
		// notifyObservers() method is called by the Observable class
		// First we check to see if the NotificationNumber is equal to this
		// thread's RegistrationNumber or SYSTEM_SHUT_DOWN.  If they are, then we
		// execute - otherwise, we stay idle.

		if ( SYSTEM_SHUT_DOWN_ID.compareTo(NotificationNumber) == 0 )
		{
			Stop = true;

		} else {
			if ( RegistrationNumber.compareTo(NotificationNumber) == 0 )
			{
				Displays Display = new Displays();
				Display.DisplayStudentList( SystemData.TheListOfStudents.ListOfStudents );

			} // if
		} // if

	} // update


   	public void run()
   	{
   		System.out.println( "\nListStudents Component Started..." );

   		try
   		{
   			while( !Stop )
            {

   				// Note this is something of a farce here.  In order to start each
    			// component as a separate thread, the run() method must be implemented.
                // To illustrate how run() could be used here I put some code here.We really
                // don't do anything here,.. but we could.  If we were doing things here,
                // whatever it was that we were doing would be interrupted when an event
                // from the executive arrived, and the update() method we would immediately
                // execute. Currently we wait forever (by 1 second increments).  Please feel
                // free to put code if if you thing you need to (not to imply that you will
                // need to).

               	Thread.sleep( 1000 );

			} // while

			System.out.println( "\nListStudents Component Shutdown..." );

		} catch (Exception e) {

			System.out.println( "Exception occured in ListStudents.run(): " + e);

		}  // try-catch

	} // run

} // ListStudents